package edu.washington.cs.workflow.analysis;

import java.util.Set;

import edu.washington.cs.workflow.analysis.AnalysisBuilder.CG;
import edu.washington.cs.workflow.analysis.AnalysisBuilder.UIFramework;
import edu.washington.cs.workflow.matching.TestGanttProject;
import edu.washington.cs.workflow.matching.TestMatchingFreemind;
import edu.washington.cs.workflow.util.Files;
import edu.washington.cs.workflow.util.Globals;
import junit.framework.TestCase;

public class TestGetAllMethod extends TestCase {
	public void testCrossword() {
		String[] pkgs = new String[]{"crosswordsage"};
		String newDir = "D:\\research\\configurations\\workspace\\workflow-error-repair\\experiments\\crossword-0.3.5.jar";
		String newMain = "Lcrosswordsage/MainScreen";
		saveMethodStatistics(newDir, newMain, pkgs, "crossword");
	}
	
	public void testGanttProject() {
		String[] pkgs = TestGanttProject.pkgs;
		String newDir = TestGanttProject.newDir;
		String newMain = TestGanttProject.main;
		saveMethodStatistics(newDir, newMain, pkgs, "ganttproject");
	}
	
	public void testJEdit() {
		String[] pkgs = new String[]{"org.gjt.sp."};
		String newDir = "D:\\research\\configurations\\workspace\\workflow-error-repair\\experiments\\jedit-2.6.jar";
		String newMain = "Lorg/gjt/sp/jedit/jEdit";
		saveMethodStatistics(newDir, newMain, pkgs, "jedit");
	}
	
	public void testJabRef() {
		String[] pkgs = new String[]{"net.sf.jabref."};
		String newDir = "D:\\research\\configurations\\workspace\\workflow-error-repair\\experiments\\jabref2.8\\JabRef-2.8.1.jar";
		String main = "Lnet/sf/jabref/JabRef";
		saveMethodStatistics(newDir, main, pkgs, "jabref");
	}
	
	public void testFreemind() {
		String[] pkgs = TestMatchingFreemind.pkgs;
		String newDir = TestMatchingFreemind.newDir;
		String newMain = TestMatchingFreemind.main;
		saveMethodStatistics(newDir, newMain, pkgs, "freemind");
	}
	
	private void saveMethodStatistics(String dir, String main, String[] pkgs, String subject) {
		AnalysisBuilder builder = new AnalysisBuilder(dir, main, pkgs);
		builder.setCGType(CG.RTA);
		builder.setUIFramework(UIFramework.SWING);
		builder.buildAnalysis();
		
		String allMethodFile = "./experiments/statistics/" + subject + "_methods.txt";
		String allHandlerFile = "./experiments/statistics/" + subject + "_handlers.txt";
		Set<String> allMethodSet = builder.getAllAppMethods();
		Set<String> allHandlerSet = builder.getAllSwingHandlers();
		
		StringBuilder sb = new StringBuilder();
		for(String m : allMethodSet) {
			sb.append(m);
			sb.append(Globals.lineSep);
		}
		Files.writeToFileNoExp(sb.toString(), allMethodFile);
		
		sb = new StringBuilder();
		for(String m : allHandlerSet) {
			sb.append(m);
			sb.append(Globals.lineSep);
		}
		Files.writeToFileNoExp(sb.toString(), allHandlerFile);
	}
}
